http://www.lowagie.com/iText/tutorial/index. html a>a more detailed tutorial. Getting Started tutorial from the start systematically introduced in the PDF file Add text, pictures, forms, etc. The methods and techniques. After reading this tutorial, you can do something more or less from the simple to the complex PDF files. However, attempts to resolve the tutorial to generate PDF documents in the course of all the difficulties is an extravagant hope. So, read the api documentation iText is very important. Download class library readers at the same time, you can download the document library. p>
in java how to use iText to generate PDF reports process p>
The following is a tutorial in the above-mentioned one of the most simple example, this example depicts a iText to generate PDF files through the normal procedure for the framework. Readers only need to document.open (); and document.close (); the middle of the two statements they want to join in on the contents of PDF documents can be. The only example of the addition of PDF file "Hello World" line of text. p>
Document document = new Document (); p>
try p>
( p>
PdfWriter.getInstance (document, new FileOutputStream ( "Chap0101.pdf ")); p>
document.open (); p>
document.add (new Paragraph ( "Hello World ")); p>
) p>
catch (DocumentException de) p>
( p>
System.err.println (de.getMessage ()); p>
) p>
catch (IOException ioe) p>
( p>
System.err.println (ioe.getMessage ()); p>
) p>
document.close (); p>
can be seen from the above example, the program's framework is very clear. However, in the PDF specified in the text, pictures, forms the location is a very troublesome thing. In addition to continually modify the location in the procedure, and then run the program, to generate PDF documents, observation of elements in the PDF in the location of such a process is reasonable, the other appears to be no better way. p>
in this part of the iText tutorial does not have an Internet-related information is also relatively small. I have seen in CSDN asked to achieve was to open with the details, it was back to achieve the principle: first on the server to generate PDF documents, and then point to the user by clicking the hyperlink PDF files download or open choice. This is an idea, or one train of thought. In this paper, the realization of this idea, and another line of thought is given through the realization of two ways. p>
1) directly on the server to generate PDF files. p>
<% @ page import = "com.lowagie.text .*, com.lowagie.text.pdf .*, java.io. *"%> p>
<% p>
String filename = "PDF" + (new Random ()). nextInt ()+". pdf "; p>
Document document = new Document (PageSize.A4); p>
ServletOutputStream out1 = response.getOutputStream (); p>
try p>
( p>
PdfWriter writer = PdfWriter.getInstance (document, new FileOutputStream (filename)); p>
document.open (); p>
document.add (new Paragraph ( "Hello World ")); p>
document.close (); p>
) p>
catch (Exception e ){}%> p>
p>
above procedure on the server to generate a static PDF document. Clearly, each running from the PDF file's name should be unique there can be heavy. This procedure generates a random function to rename the PDF file. Shortcomings of this procedure is that each run on the server will generate a PDF file, if not promptly removed, the number of growing sites is obviously defenders do not want to see.